package com.squirrelhuan.quickhttp_sample

import com.google.gson.JsonObject
import io.reactivex.Observable
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Headers
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface Api {

    @POST("/api/v1/authentication/login")
    suspend fun authentication(
        @Header("x-api-key") apiKey: String,
        @Header("x-client-id") clientId: String
    ): ResponseBody

    @POST("/api/v1/authentication/login")
    fun authenticationSynchronous(
        @Header("x-api-key") apiKey: String,
        @Header("x-client-id") clientId: String
    ): Call<ResponseBody>

    @POST("/api/v1/pa/payment_intents/create")
    suspend fun createPaymentIntent(@Body params: MutableMap<String, Any>): ResponseBody

    @POST("/api/v1/pa/customers/create")
    suspend fun createCustomer(@Body params: MutableMap<String, Any>): ResponseBody

    @GET("/api/v1/pa/customers/{id}/generate_client_secret")
    fun createClientSecretSynchronous(@Path("id") customId: String): Call<ResponseBody>

    //get请求
    @GET(URLConstant.URL_UPDATE_APP)
    fun getSession(): Observable<Any?>?

    //get带参数请求
    @GET(URLConstant.URL_BASE)
    fun getWithParam(@Query("context") context: String?): Observable<Any?>?

    //get请求
    @GET(URLConstant.URL_UPDATE_APP)
    fun getVersion(): Observable<Any?>?

    @FormUrlEncoded
    @POST(URLConstant.URL_BASE)
    fun getPostRequest(): Observable<Any?>?

    @Headers("Content-Type: application/json", "Accept: application/json")
    @POST(URLConstant.URL_BASE)
    fun getUserInfo(@Body body: RequestBody?): Observable<Any?>?


    //get请求
    @POST(URLConstant.uploadFile)
    fun uploadHeaderImg(userId: String?, body: MultipartBody.Part?): Observable<Any?>?

    /**
     * 蒲公英查看最新app版本
     * @param _api_key
     * @param appKey
     * @return
     */
    @FormUrlEncoded
    @POST("https://www.pgyer.com/apiv2/app/check")
    fun checkAppVersion(
        @Field("_api_key") _api_key: String?,
        @Field("appKey") appKey: String?
    ): Observable<JsonObject?>?
}